<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: Adding (blending) two images using OpenCV</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../d9/df8/tutorial_root.html">OpenCV Tutorials</a></li><li class="navelem"><a class="el" href="../../de/d7a/tutorial_table_of_content_core.html">The Core Functionality (core module)</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Adding (blending) two images using OpenCV </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><b>Prev Tutorial:</b> <a class="el" href="../../d5/d98/tutorial_mat_operations.html">Operations with images</a></p>
<p><b>Next Tutorial:</b> <a class="el" href="../../d3/dc1/tutorial_basic_linear_transform.html">Changing the contrast and brightness of an image!</a></p>
<table class="doxtable">
<tr>
<th align="right"></th><th align="left"></th></tr>
<tr>
<td align="right">Original author </td><td align="left">Ana Huamán </td></tr>
<tr>
<td align="right">Compatibility </td><td align="left">OpenCV &gt;= 3.0 </td></tr>
</table>
<p>We will learn how to blend two images! </p><h2>Goal </h2>
<p>In this tutorial you will learn:</p>
<ul>
<li>what is <em>linear blending</em> and why it is useful;</li>
<li>how to add two images using <b><a class="el" href="../../d2/de8/group__core__array.html#gafafb2513349db3bcff51f54ee5592a19" title="Calculates the weighted sum of two arrays. ">addWeighted()</a></b></li>
</ul>
<h2>Theory </h2>
<dl class="section note"><dt>Note</dt><dd>The explanation below belongs to the book <a href="http://szeliski.org/Book/">Computer Vision: Algorithms and Applications</a> by Richard Szeliski</dd></dl>
<p>From our previous tutorial, we know already a bit of <em>Pixel operators</em>. An interesting dyadic (two-input) operator is the <em>linear blend operator</em>:</p>
<p class="formulaDsp">
\[g(x) = (1 - \alpha)f_{0}(x) + \alpha f_{1}(x)\]
</p>
<p>By varying \(\alpha\) from \(0 \rightarrow 1\) this operator can be used to perform a temporal <em>cross-dissolve</em> between two images or videos, as seen in slide shows and film productions (cool, eh?)</p>
<h2>Source Code </h2>
 <div class='newInnerHTML' title='cpp' style='display: none;'>C++</div><div class='toggleable_div label_cpp' style='display: none;'><p> Download the source code from <a href="https://raw.githubusercontent.com/opencv/opencv/master/samples/cpp/tutorial_code/core/AddingImages/AddingImages.cpp">here</a>. </p><div class="fragment"><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="../../d6/d87/imgcodecs_8hpp.html">opencv2/imgcodecs.hpp</a>&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="../../d4/dd5/highgui_8hpp.html">opencv2/highgui.hpp</a>&quot;</span></div><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d2/d75/namespacecv.html">cv</a>;</div><div class="line"></div><div class="line"><span class="comment">// we&#39;re NOT &quot;using namespace std;&quot; here, to avoid collisions between the beta variable and std::beta in c++17</span></div><div class="line"><span class="keyword">using</span> std::cin;</div><div class="line"><span class="keyword">using</span> std::cout;</div><div class="line"><span class="keyword">using</span> std::endl;</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main( <span class="keywordtype">void</span> )</div><div class="line">{</div><div class="line">   <span class="keywordtype">double</span> alpha = 0.5; <span class="keywordtype">double</span> beta; <span class="keywordtype">double</span> input;</div><div class="line"></div><div class="line">   <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> src1, src2, dst;</div><div class="line"></div><div class="line">   cout &lt;&lt; <span class="stringliteral">&quot; Simple Linear Blender &quot;</span> &lt;&lt; endl;</div><div class="line">   cout &lt;&lt; <span class="stringliteral">&quot;-----------------------&quot;</span> &lt;&lt; endl;</div><div class="line">   cout &lt;&lt; <span class="stringliteral">&quot;* Enter alpha [0.0-1.0]: &quot;</span>;</div><div class="line">   cin &gt;&gt; input;</div><div class="line"></div><div class="line">   <span class="comment">// We use the alpha provided by the user if it is between 0 and 1</span></div><div class="line">   <span class="keywordflow">if</span>( input &gt;= 0 &amp;&amp; input &lt;= 1 )</div><div class="line">     { alpha = input; }</div><div class="line"></div><div class="line">   src1 = <a class="code" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">imread</a>( <a class="code" href="../../d6/dba/group__core__utils__samples.html#ga3a33b00033b46c698ff6340d95569c13">samples::findFile</a>(<span class="stringliteral">&quot;LinuxLogo.jpg&quot;</span>) );</div><div class="line">   src2 = <a class="code" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">imread</a>( <a class="code" href="../../d6/dba/group__core__utils__samples.html#ga3a33b00033b46c698ff6340d95569c13">samples::findFile</a>(<span class="stringliteral">&quot;WindowsLogo.jpg&quot;</span>) );</div><div class="line"></div><div class="line">   <span class="keywordflow">if</span>( src1.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abbec3525a852e77998aba034813fded4">empty</a>() ) { cout &lt;&lt; <span class="stringliteral">&quot;Error loading src1&quot;</span> &lt;&lt; endl; <span class="keywordflow">return</span> EXIT_FAILURE; }</div><div class="line">   <span class="keywordflow">if</span>( src2.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abbec3525a852e77998aba034813fded4">empty</a>() ) { cout &lt;&lt; <span class="stringliteral">&quot;Error loading src2&quot;</span> &lt;&lt; endl; <span class="keywordflow">return</span> EXIT_FAILURE; }</div><div class="line"></div><div class="line">   beta = ( 1.0 - alpha );</div><div class="line">   <a class="code" href="../../d2/de8/group__core__array.html#gafafb2513349db3bcff51f54ee5592a19">addWeighted</a>( src1, alpha, src2, beta, 0.0, dst);</div><div class="line"></div><div class="line">   <a class="code" href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">imshow</a>( <span class="stringliteral">&quot;Linear Blend&quot;</span>, dst );</div><div class="line">   <a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">waitKey</a>(0);</div><div class="line"></div><div class="line">   <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment -->  </div>  <div class='newInnerHTML' title='java' style='display: none;'>Java</div><div class='toggleable_div label_java' style='display: none;'><p> Download the source code from <a href="https://raw.githubusercontent.com/opencv/opencv/master/samples/java/tutorial_code/core/AddingImages/AddingImages.java">here</a>. </p><div class="fragment"><div class="line"><span class="keyword">import</span> org.opencv.core.*;</div><div class="line"><span class="keyword">import</span> org.opencv.highgui.HighGui;</div><div class="line"><span class="keyword">import</span> org.opencv.imgcodecs.Imgcodecs;</div><div class="line"></div><div class="line"><span class="keyword">import</span> java.util.Locale;</div><div class="line"><span class="keyword">import</span> java.util.Scanner;</div><div class="line"></div><div class="line"><span class="keyword">class </span>AddingImagesRun{</div><div class="line">    <span class="keyword">public</span> <span class="keywordtype">void</span> run() {</div><div class="line">        <span class="keywordtype">double</span> alpha = 0.5; <span class="keywordtype">double</span> beta; <span class="keywordtype">double</span> input;</div><div class="line"></div><div class="line">        Mat src1, src2, dst = <span class="keyword">new</span> Mat();</div><div class="line"></div><div class="line">        System.out.println(<span class="stringliteral">&quot; Simple Linear Blender &quot;</span>);</div><div class="line">        System.out.println(<span class="stringliteral">&quot;-----------------------&quot;</span>);</div><div class="line">        System.out.println(<span class="stringliteral">&quot;* Enter alpha [0.0-1.0]: &quot;</span>);</div><div class="line">        Scanner scan = <span class="keyword">new</span> Scanner( System.in ).useLocale(Locale.US);</div><div class="line">        input = scan.nextDouble();</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span>( input &gt;= 0.0 &amp;&amp; input &lt;= 1.0 )</div><div class="line">            alpha = input;</div><div class="line"></div><div class="line">        src1 = Imgcodecs.imread(<span class="stringliteral">&quot;../../images/LinuxLogo.jpg&quot;</span>);</div><div class="line">        src2 = Imgcodecs.imread(<span class="stringliteral">&quot;../../images/WindowsLogo.jpg&quot;</span>);</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span>( src1.empty() == true ){ System.out.println(<span class="stringliteral">&quot;Error loading src1&quot;</span>); <span class="keywordflow">return</span>;}</div><div class="line">        <span class="keywordflow">if</span>( src2.empty() == true ){ System.out.println(<span class="stringliteral">&quot;Error loading src2&quot;</span>); <span class="keywordflow">return</span>;}</div><div class="line"></div><div class="line">        beta = ( 1.0 - alpha );</div><div class="line">        Core.addWeighted( src1, alpha, src2, beta, 0.0, dst);</div><div class="line"></div><div class="line">        HighGui.imshow(<span class="stringliteral">&quot;Linear Blend&quot;</span>, dst);</div><div class="line">        HighGui.waitKey(0);</div><div class="line"></div><div class="line">        System.exit(0);</div><div class="line">    }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">public</span> <span class="keyword">class </span>AddingImages {</div><div class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keywordtype">void</span> main(<a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a>[] args) {</div><div class="line">        <span class="comment">// Load the native library.</span></div><div class="line">        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);</div><div class="line">        <span class="keyword">new</span> AddingImagesRun().run();</div><div class="line">    }</div><div class="line">}</div></div><!-- fragment -->  </div>  <div class='newInnerHTML' title='python' style='display: none;'>Python</div><div class='toggleable_div label_python' style='display: none;'><p> Download the source code from <a href="https://raw.githubusercontent.com/opencv/opencv/master/samples/python/tutorial_code/core/AddingImages/adding_images.py">here</a>. </p><div class="fragment"><div class="line"><span class="keyword">from</span> __future__ <span class="keyword">import</span> print_function</div><div class="line"></div><div class="line"><span class="keyword">import</span> cv2 <span class="keyword">as</span> cv</div><div class="line"></div><div class="line">alpha = 0.5</div><div class="line"></div><div class="line"><span class="keywordflow">try</span>:</div><div class="line">    raw_input          <span class="comment"># Python 2</span></div><div class="line"><span class="keywordflow">except</span> NameError:</div><div class="line">    raw_input = input  <span class="comment"># Python 3</span></div><div class="line"></div><div class="line"><a class="code" href="../../df/d57/namespacecv_1_1dnn.html#a701210a0203f2786cbfd04b2bd56da47">print</a>(<span class="stringliteral">&#39;&#39;&#39; Simple Linear Blender</span></div><div class="line"><span class="stringliteral">-----------------------</span></div><div class="line"><span class="stringliteral">* Enter alpha [0.0-1.0]: &#39;&#39;&#39;</span>)</div><div class="line">input_alpha = float(raw_input().<a class="code" href="../../d2/daf/namespacecv_1_1detail.html#aa3e0fd33a9587046335f9eb87e399f67">strip</a>())</div><div class="line"><span class="keywordflow">if</span> 0 &lt;= alpha &lt;= 1:</div><div class="line">    alpha = input_alpha</div><div class="line"><span class="comment"># [load]</span></div><div class="line">src1 = <a class="code" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">cv.imread</a>(<a class="code" href="../../d6/dba/group__core__utils__samples.html#ga3a33b00033b46c698ff6340d95569c13">cv.samples.findFile</a>(<span class="stringliteral">&#39;LinuxLogo.jpg&#39;</span>))</div><div class="line">src2 = <a class="code" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">cv.imread</a>(<a class="code" href="../../d6/dba/group__core__utils__samples.html#ga3a33b00033b46c698ff6340d95569c13">cv.samples.findFile</a>(<span class="stringliteral">&#39;WindowsLogo.jpg&#39;</span>))</div><div class="line"><span class="comment"># [load]</span></div><div class="line"><span class="keywordflow">if</span> src1 <span class="keywordflow">is</span> <span class="keywordtype">None</span>:</div><div class="line">    <a class="code" href="../../df/d57/namespacecv_1_1dnn.html#a701210a0203f2786cbfd04b2bd56da47">print</a>(<span class="stringliteral">&quot;Error loading src1&quot;</span>)</div><div class="line">    exit(-1)</div><div class="line"><span class="keywordflow">elif</span> src2 <span class="keywordflow">is</span> <span class="keywordtype">None</span>:</div><div class="line">    <a class="code" href="../../df/d57/namespacecv_1_1dnn.html#a701210a0203f2786cbfd04b2bd56da47">print</a>(<span class="stringliteral">&quot;Error loading src2&quot;</span>)</div><div class="line">    exit(-1)</div><div class="line"><span class="comment"># [blend_images]</span></div><div class="line">beta = (1.0 - alpha)</div><div class="line">dst = <a class="code" href="../../d2/de8/group__core__array.html#gafafb2513349db3bcff51f54ee5592a19">cv.addWeighted</a>(src1, alpha, src2, beta, 0.0)</div><div class="line"><span class="comment"># [blend_images]</span></div><div class="line"><span class="comment"># [display]</span></div><div class="line"><a class="code" href="../../df/d24/group__highgui__opengl.html#gaae7e90aa3415c68dba22a5ff2cefc25d">cv.imshow</a>(<span class="stringliteral">&#39;dst&#39;</span>, dst)</div><div class="line"><a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">cv.waitKey</a>(0)</div><div class="line"><span class="comment"># [display]</span></div><div class="line"><a class="code" href="../../d7/dfc/group__highgui.html#ga6b7fc1c1a8960438156912027b38f481">cv.destroyAllWindows</a>()</div></div><!-- fragment -->  </div> <h2>Explanation </h2>
<p>Since we are going to perform:</p>
<p class="formulaDsp">
\[g(x) = (1 - \alpha)f_{0}(x) + \alpha f_{1}(x)\]
</p>
<p>We need two source images ( \(f_{0}(x)\) and \(f_{1}(x)\)). So, we load them in the usual way: </p> <div class='newInnerHTML' title='cpp' style='display: none;'>C++</div><div class='toggleable_div label_cpp' style='display: none;'> <div class="fragment"><div class="line">   src1 = <a class="code" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">imread</a>( <a class="code" href="../../d6/dba/group__core__utils__samples.html#ga3a33b00033b46c698ff6340d95569c13">samples::findFile</a>(<span class="stringliteral">&quot;LinuxLogo.jpg&quot;</span>) );</div><div class="line">   src2 = <a class="code" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">imread</a>( <a class="code" href="../../d6/dba/group__core__utils__samples.html#ga3a33b00033b46c698ff6340d95569c13">samples::findFile</a>(<span class="stringliteral">&quot;WindowsLogo.jpg&quot;</span>) );</div></div><!-- fragment --> </div>  <div class='newInnerHTML' title='java' style='display: none;'>Java</div><div class='toggleable_div label_java' style='display: none;'> <div class="fragment"><div class="line">        src1 = Imgcodecs.imread(<span class="stringliteral">&quot;../../images/LinuxLogo.jpg&quot;</span>);</div><div class="line">        src2 = Imgcodecs.imread(<span class="stringliteral">&quot;../../images/WindowsLogo.jpg&quot;</span>);</div></div><!-- fragment --> </div>  <div class='newInnerHTML' title='python' style='display: none;'>Python</div><div class='toggleable_div label_python' style='display: none;'> <div class="fragment"><div class="line">src1 = <a class="code" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">cv.imread</a>(<a class="code" href="../../d6/dba/group__core__utils__samples.html#ga3a33b00033b46c698ff6340d95569c13">cv.samples.findFile</a>(<span class="stringliteral">&#39;LinuxLogo.jpg&#39;</span>))</div><div class="line">src2 = <a class="code" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">cv.imread</a>(<a class="code" href="../../d6/dba/group__core__utils__samples.html#ga3a33b00033b46c698ff6340d95569c13">cv.samples.findFile</a>(<span class="stringliteral">&#39;WindowsLogo.jpg&#39;</span>))</div></div><!-- fragment --> </div> <p>We used the following images: <a href="https://raw.githubusercontent.com/opencv/opencv/master/samples/data/LinuxLogo.jpg">LinuxLogo.jpg</a> and <a href="https://raw.githubusercontent.com/opencv/opencv/master/samples/data/WindowsLogo.jpg">WindowsLogo.jpg</a></p>
<dl class="section warning"><dt>Warning</dt><dd>Since we are <em>adding</em> <em>src1</em> and <em>src2</em>, they both have to be of the same size (width and height) and type.</dd></dl>
<p>Now we need to generate the <code>g(x)</code> image. For this, the function <b><a class="el" href="../../d2/de8/group__core__array.html#gafafb2513349db3bcff51f54ee5592a19" title="Calculates the weighted sum of two arrays. ">addWeighted()</a></b> comes quite handy:</p>
 <div class='newInnerHTML' title='cpp' style='display: none;'>C++</div><div class='toggleable_div label_cpp' style='display: none;'> <div class="fragment"><div class="line">   beta = ( 1.0 - alpha );</div><div class="line">   <a class="code" href="../../d2/de8/group__core__array.html#gafafb2513349db3bcff51f54ee5592a19">addWeighted</a>( src1, alpha, src2, beta, 0.0, dst);</div></div><!-- fragment --> </div>  <div class='newInnerHTML' title='java' style='display: none;'>Java</div><div class='toggleable_div label_java' style='display: none;'> <div class="fragment"><div class="line">        beta = ( 1.0 - alpha );</div><div class="line">        Core.addWeighted( src1, alpha, src2, beta, 0.0, dst);</div></div><!-- fragment --> </div>  <div class='newInnerHTML' title='python' style='display: none;'>Python</div><div class='toggleable_div label_python' style='display: none;'> <div class="fragment"><div class="line">beta = (1.0 - alpha)</div><div class="line">dst = <a class="code" href="../../d2/de8/group__core__array.html#gafafb2513349db3bcff51f54ee5592a19">cv.addWeighted</a>(src1, alpha, src2, beta, 0.0)</div></div><!-- fragment --><p>Numpy version of above line (but cv function is around 2x faster): </p><div class="fragment"><div class="line">dst = np.uint8(alpha*(img1)+beta*(img2))</div></div><!-- fragment -->  </div> <p>since <b><a class="el" href="../../d2/de8/group__core__array.html#gafafb2513349db3bcff51f54ee5592a19" title="Calculates the weighted sum of two arrays. ">addWeighted()</a></b> produces: </p><p class="formulaDsp">
\[dst = \alpha \cdot src1 + \beta \cdot src2 + \gamma\]
</p>
<p> In this case, <code>gamma</code> is the argument \(0.0\) in the code above.</p>
<p>Create windows, show the images and wait for the user to end the program. </p> <div class='newInnerHTML' title='cpp' style='display: none;'>C++</div><div class='toggleable_div label_cpp' style='display: none;'> <div class="fragment"><div class="line">   <a class="code" href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">imshow</a>( <span class="stringliteral">&quot;Linear Blend&quot;</span>, dst );</div><div class="line">   <a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">waitKey</a>(0);</div></div><!-- fragment --> </div>  <div class='newInnerHTML' title='java' style='display: none;'>Java</div><div class='toggleable_div label_java' style='display: none;'> <div class="fragment"><div class="line">        HighGui.imshow(<span class="stringliteral">&quot;Linear Blend&quot;</span>, dst);</div><div class="line">        HighGui.waitKey(0);</div></div><!-- fragment --> </div>  <div class='newInnerHTML' title='python' style='display: none;'>Python</div><div class='toggleable_div label_python' style='display: none;'> <div class="fragment"><div class="line"><a class="code" href="../../df/d24/group__highgui__opengl.html#gaae7e90aa3415c68dba22a5ff2cefc25d">cv.imshow</a>(<span class="stringliteral">&#39;dst&#39;</span>, dst)</div><div class="line"><a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">cv.waitKey</a>(0)</div></div><!-- fragment --> </div> <h2>Result </h2>
<div class="image">
<img src="../../Adding_Images_Tutorial_Result_Big.jpg" alt="Adding_Images_Tutorial_Result_Big.jpg"/>
</div>
 </div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:34 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
